package com.imooc.op_data

import java.sql.{Connection, DriverManager}

object MySqlApp extends App {

  val url = "jdbc:mysql://192.168.1.103/mysql"
  val username = "root"
  val password = "123456"

  var connection:Connection = null

  try {

    classOf[com.mysql.jdbc.Driver]

    connection = DriverManager.getConnection(url, username, password)
    val statement = connection.createStatement()
    val resultSet = statement.executeQuery("select host,user from user ")
    while (resultSet.next()) {
      val host = resultSet.getString("host")
      val user = resultSet.getString("user")

      println(s"$host,$user")

    }
  }catch {
    case e:Exception => e.printStackTrace()
  }finally {

    if(connection == null){
      connection.close()
    }

  }


}
